import os
import board
import busio
import adafruit_ssd1306
from time import sleep

# 字体文件
font_file = 'font5x8.bin'

# 构建I2C对象
i2c = busio.I2C(board.SCL2, board.SDA2)

# 构建OLED对象,01Studio配套的OLED地址为0x3C
display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C)

# 清空显示屏
display.fill(0)
display.show()

# 定义字符的像素表示
char_map = {
    'P': [
        "11110",
        "10001",
        "10001",
        "11110",
        "10000",
        "10000",
        "10000",
    ],
    'a': [
        "00000",
        "01110",
        "10010",
        "11111",
        "10010",
        "10010",
        "01101",
    ],
    'y': [
        "00000",
        "10001",
        "10001",
        "10001",
        "01111",
        "00001",
        "11110",
    ],
    '4': [
        "00100",
        "01100",
        "10100",
        "10100",
        "11111",
        "00100",
        "00100",
    ],
    't': [
        "00100",
        "11111",
        "00100",
        "00100",
        "00100",
        "00101",
        "00010",
    ],
}

# 定义字符间距和初始位置
char_width = 6
char_height = 7
scale = 3  # 放大比例
x_offset = 0
y_offset = 20  # 调整Y轴偏移以居中显示

# 绘制字符
text = "Pay4att"
for char in text:
    char_pixels = char_map.get(char, ["00000"] * 7)
    for y, row in enumerate(char_pixels):
        for x, pixel in enumerate(row):
            if pixel == "1":
                # 绘制放大后的像素
                for dx in range(scale):
                    for dy in range(scale):
                        display.pixel(x * scale + dx + x_offset, y * scale + dy + y_offset, 1)
    x_offset += char_width * scale

# 更新显示屏
display.show()